package kr.saeildamil.androidstudy_second.br_service;

import java.util.Random;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class LocalService extends Service {
	private final IBinder mBinder = new LocalBinder();
	private final Random mGen = new Random();
	
	class LocalBinder extends Binder{
		LocalService getService(){
			Log.d("LocalBinder", "getService()");
			return LocalService.this;
		}
	}
	
	@Override
	public void onCreate() {
		Log.d("LocalService", "onCreate()");
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.d("LocalService", "onStartCommand()");
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		Log.d("LocalService", "onDestroy()");
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.d("LocalService", "onBind()");
		return mBinder;
	}

	//Activity (클라이언트)가 호출하는 메소드
	public int getRandomNumber(){
		Log.d("LocalService", "getRandomNumber()");
		return mGen.nextInt(100);
	}
	
	public int getSum(int a, int b){
		return a+b;
	}
}
